package com.pp.tourism.web.dto;

import com.pp.tourism.web.exception.ApiRtnCode;
import lombok.AllArgsConstructor;
import lombok.Data;

import static com.pp.tourism.web.exception.ApiRtnCode.OK;

/**
 * api统一返回格式
 *
 */
@AllArgsConstructor
@Data
public class ApiResponse<T> {

    private String code;
    private String message;
    private T data;

    public static ApiResponse ok() {
        return ok(null);
    }

    public static <T> ApiResponse ok(T data) {
        return new ApiResponse<>(OK.getCode(), OK.getMsg(), data);
    }

    public static ApiResponse error(ApiRtnCode code) {
        return error(code, null);
    }
    public static ApiResponse error(String code , String msg ) {
        return new ApiResponse<>(code, msg,null);
    }

    public static <T> ApiResponse error(ApiRtnCode code, T data) {
        return new ApiResponse<>(code.getCode(), code.getMsg(), data);
    }
}
